package com.sandking.db.bean;

import com.sandking.tools.SK_Map;
import java.util.ArrayList;
import com.sandking.db.cache.YhfkCache;
import com.alibaba.fastjson.JSON;
import java.util.Map;
import com.sandking.io.SK_OutputStream;
import java.util.List;
import com.sandking.io.SK_InputStream;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;

/**
 * 用户反馈
 */
public class Yhfk {

	public static final String TABLENAME = "用户反馈";
	public static final String CLASSNAME = "Yhfk"; 
	/**
	 * 需要更新字段集
	 */
	private Map<String, Object> updateColumns;

	/** id */
	private int id;
	
	/** 反馈人id */
	private int fkrid;
	
	/** 反馈人昵称 */
	private int fkrnc;
	
	/** 内容 */
	private String nr;
	
	/** 反馈时间 */
	private java.util.Date fksj;
	
	
	public Yhfk() {
		super();
	}
	
	public Yhfk(int id, int fkrid, int fkrnc, String nr, java.util.Date fksj) {
		super();
		this.id = id;
		this.fkrid = fkrid;
		this.fkrnc = fkrnc;
		this.nr = nr;
		this.fksj = fksj;
	}
	
	public Map<String, Object> getUpdateColumns() {
		if(updateColumns == null)
			updateColumns = new HashMap<String, Object>();
		return updateColumns;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
		addUpdateColumn("id",id);
	}
	
	public void changeIdWith(int id){
		this.id += id;
		setId(this.id);
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}	
	public int getFkrid() {
		return fkrid;
	}
	
	public void setFkrid(int fkrid) {
		this.fkrid = fkrid;
		addUpdateColumn("反馈人id",fkrid);
	}
	
	public void changeFkridWith(int fkrid){
		this.fkrid += fkrid;
		setFkrid(this.fkrid);
	}
	
	public void changeFkridWithMin(int fkrid,int min){
		this.fkrid += fkrid;
		this.fkrid = this.fkrid < min ? min : this.fkrid;
		setFkrid(this.fkrid);
	}
	
	public void changeFkridWithMax(int fkrid,int max){
		this.fkrid += fkrid;
		this.fkrid = this.fkrid > max ? max : this.fkrid;
		setFkrid(this.fkrid);
	}
	
	public void changeFkridWithMaxMin(int fkrid,int max,int min){
		this.fkrid += fkrid;
		this.fkrid = this.fkrid < min ? min : this.fkrid;
		this.fkrid = this.fkrid > max ? max : this.fkrid;
		setFkrid(this.fkrid);
	}	
	public int getFkrnc() {
		return fkrnc;
	}
	
	public void setFkrnc(int fkrnc) {
		this.fkrnc = fkrnc;
		addUpdateColumn("反馈人昵称",fkrnc);
	}
	
	public void changeFkrncWith(int fkrnc){
		this.fkrnc += fkrnc;
		setFkrnc(this.fkrnc);
	}
	
	public void changeFkrncWithMin(int fkrnc,int min){
		this.fkrnc += fkrnc;
		this.fkrnc = this.fkrnc < min ? min : this.fkrnc;
		setFkrnc(this.fkrnc);
	}
	
	public void changeFkrncWithMax(int fkrnc,int max){
		this.fkrnc += fkrnc;
		this.fkrnc = this.fkrnc > max ? max : this.fkrnc;
		setFkrnc(this.fkrnc);
	}
	
	public void changeFkrncWithMaxMin(int fkrnc,int max,int min){
		this.fkrnc += fkrnc;
		this.fkrnc = this.fkrnc < min ? min : this.fkrnc;
		this.fkrnc = this.fkrnc > max ? max : this.fkrnc;
		setFkrnc(this.fkrnc);
	}	
	public String getNr() {
		return nr;
	}
	
	public void setNr(String nr) {
		this.nr = nr;
		addUpdateColumn("内容",nr);
	}
	
	public java.util.Date getFksj() {
		return fksj;
	}
	
	public void setFksj(java.util.Date fksj) {
		this.fksj = fksj;
		addUpdateColumn("反馈时间",fksj);
	}
	
	
	public void addUpdateColumn(String key, Object val) {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.put(key, val);
	}
	
	public void clearUpdateColumn() {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.clear();
	}
	
	public Map<String, Object> toMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("fkrid", this.fkrid);
        result.put("fkrnc", this.fkrnc);
        result.put("nr", this.nr);
        result.put("fksj", this.fksj);
        return result;
    }
    
    public String toString(){
        return toMap().toString();
    }
    
    public String toJson(){
    	return JSON.toJSONString(toMap());
    }
    
    /**
     * 数据库源字段Map
     */
    public Map<String, Object> toColumnNameMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("反馈人id", this.fkrid);
        result.put("反馈人昵称", this.fkrnc);
        result.put("内容", this.nr);
        result.put("反馈时间", this.fksj);
        return result;
    }
    
    public String toColumnNameString(){
        return toColumnNameMap().toString();
    }
    
    public byte[] toBytes() throws Exception {
    	try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
		    SK_OutputStream.writeInt(out,this.id);
		    SK_OutputStream.writeInt(out,this.fkrid);
		    SK_OutputStream.writeInt(out,this.fkrnc);
		    SK_OutputStream.writeString(out,this.nr);
		    return out.toByteArray();
    	}catch (Exception e) {
            throw e;
        }
    }
    
     public static Yhfk createForBytes(byte[] _byte) throws Exception {
     	try (ByteArrayInputStream in = new ByteArrayInputStream(_byte);) {
	     	Yhfk yhfk = new Yhfk();
		    yhfk.id = SK_InputStream.readInt(in,null);
		    yhfk.fkrid = SK_InputStream.readInt(in,null);
		    yhfk.fkrnc = SK_InputStream.readInt(in,null);
		    yhfk.nr = SK_InputStream.readString(in,null);
		    return yhfk;
    	}catch (Exception e) {
            throw e;
        }
     }
    
    /**
     * 根据list创建对象
     */
    public static List<Yhfk> createForColumnNameList(List<Map<String, Object>> list){
    	List<Yhfk> yhfks = new ArrayList<Yhfk>();
		for (Map<String, Object> map : list) {
			yhfks.add(createForColumnNameMap(map));
		}
		return yhfks;
    }
    
    /**
     * 根据map创建对象
     */
    public static Yhfk createForColumnNameMap(Map<String, Object> map){
    	Yhfk obj = new Yhfk();
	    obj.id = SK_Map.getInt("id", map);
	    obj.fkrid = SK_Map.getInt("反馈人id", map);
	    obj.fkrnc = SK_Map.getInt("反馈人昵称", map);
	    obj.nr = SK_Map.getString("内容", map);
        return obj;
    }
    
    /**
     * 根据list创建对象
     */
    public static List<Yhfk> createForList(List<Map<String, Object>> list){
    	List<Yhfk> yhfks = new ArrayList<Yhfk>();
		for (Map<String, Object> map : list) {
			yhfks.add(createForColumnNameMap(map));
		}
		return yhfks;
    }
    
    /**
     * 根据map创建对象
     */
    public static Yhfk createForMap(Map<String, Object> map){
    	Yhfk obj = new Yhfk();
	    obj.id = SK_Map.getInt("id", map);
	    obj.fkrid = SK_Map.getInt("fkrid", map);
	    obj.fkrnc = SK_Map.getInt("fkrnc", map);
	    obj.nr = SK_Map.getString("nr", map);
        return obj;
    }
    
    public static Yhfk createForJson(String json){
    	Map<String, Object> map = JSON.parseObject(json);
    	return createForMap(map);
    }
    
    public static List<Yhfk> createForJson(List<String> jsons){
    	List<Yhfk> yhfks = new ArrayList<Yhfk>();
    	for(String json : jsons){
    		yhfks.add(createForJson(json));
    	}
    	return yhfks;
    }
    
    /** 延迟插入数据库 */
    public Yhfk insert(){
    	return YhfkCache.insert(this);
    }
    /** 延迟更新数据库 */
    public Yhfk update(){
    	return YhfkCache.update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return YhfkCache.delete(this);
    }
    /** 即时插入数据库 */
    public Yhfk insertAndFlush(){
    	return YhfkCache.insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Yhfk updateAndFlush(){
    	return YhfkCache.updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return YhfkCache.deleteAndFlush(this);
    }
}